# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Roman Kyrylych <roman@archlinux.org>
# Contributor: Johannes Sjolund <j.sjolund@gmail.com>

pkgbase=mxml
pkgname=(mxml mxml-docs)
pkgver=3.3.1
pkgrel=1
pkgdesc="A small XML parsing library"
arch=(loong64 x86_64)
url="https://www.msweet.org/mxml"
license=(LGPL)
options=(debug)
source=($pkgname-$pkgver.tar.gz::https://github.com/michaelrsweet/$pkgname/archive/v$pkgver.tar.gz)
sha512sums=('43e6a92806d9c3f5db39fbf960c15ebfa6d92ef98274b7ce39b57724d6c26ad4362d6d8f3c1023efda92e6a815df068e5038a0cd479562b6be9dbdda8e827a41')
b2sums=('e0d599fd947dfef72edae40c1e70ea76c92105128dd46e772a7c71f9293cab3339c980396dffe105246cad64d0474935cc1939005ad9a2bffc8e8107f025a466')

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

build() {
  cd $pkgbase-$pkgver
  ./configure \
    --prefix=/usr \
    --enable-shared
  make
}

package_mxml() {
  depends=(glibc)
  optdepends=('mxml-docs: for documentation')
  provides=(libmxml.so)

  make DSTROOT="$pkgdir" install -C $pkgbase-$pkgver

  cd "$pkgdir"
  _pick mxml-docs usr/share/doc/$pkgbase/*.{epub,html,png}
}

package_mxml-docs() {
  pkgdesc+=" - documentation"

  mv -v $pkgname/* "$pkgdir"
}
